package com.easyfun.healthmagicbox.comm.json;

import org.json.JSONException;
import org.json.JSONObject;

import com.easyfun.healthmagicbox.pojo.PersonProfile;
import com.easyfun.healthmagicbox.pojo.TopHealth;

public class TopHealthJsonWrapper<T extends JsonWrapper> extends
		AbstractJsonWrapper<T, PersonProfile> {
	TopHealth mpp;

	public TopHealthJsonWrapper(TopHealth pp) {
		mpp = pp;
	}

	public TopHealthJsonWrapper() {
	}

	public TopHealth getMpp() {
		return mpp;
	}

	public void deserializeFromObj(JSONObject obj) throws JSONException {
		if (mpp == null) {
			mpp = new TopHealth();
		}
		mpp.setPersonID(obj.getString("personID"));
		mpp.setValueData(obj.getString("valueData"));
		if (obj.isNull("valueType"))
    	{
    		mpp.setValueType(Integer.valueOf(0));
    	}else
    		mpp.setValueType(obj.getInt("valueType"));

		mpp.setTopInfo(obj.getString("topInfo"));
		mpp.setTopResult(obj.getString("topResult"));

		if (obj.isNull("topNumberInBox"))
    	{
    		mpp.setTopNumberInBox(Integer.valueOf(0));
    	}else
    		mpp.setTopNumberInBox(obj.getInt("topNumberInBox"));
		if (obj.isNull("topNumberInNation"))
    	{
    		mpp.setTopNumberInNation(Integer.valueOf(0));
    	}else
    		mpp.setTopNumberInNation(obj.getInt("topNumberInNation"));
	}

	public JSONObject serializeToObj() throws JSONException {
		JSONObject serializedObj = new JSONObject();
		serializedObj.put("personID", mpp.getPersonID());
		serializedObj.put("valueData", mpp.getValueData());
		serializedObj.put("valueType", mpp.getValueType());
		serializedObj.put("topInfo", mpp.getTopInfo());
		serializedObj.put("topResult", mpp.getTopResult());
		serializedObj.put("topNumberInNation", mpp.getTopNumberInNation());
		serializedObj.put("topNumberInBox", mpp.getTopNumberInBox());
		return serializedObj;

	}

}
